#include "hzpch.h"
#include "Renderer.h"

#include "Hazel/platform/OpenGL/OpenGLShader.h"
#include "Renderer2D.h"
namespace Hazel {

    Renderer::SceneData* Renderer::s_SceneData = new Renderer::SceneData;

    void Renderer::Init()
    {
        HZ_PROFILE_FUNC();
        
        RendererCommand::Init();
        Renderer2D::Init();
    }
    void Renderer::OnWindowResize(uint32_t width, uint32_t height)
    {
        RendererCommand::SetViewport(0, 0, width, height);
    }
    void Renderer::BeginScene(OrthographicCamera &camera)
    {
        s_SceneData->ViewProjectionMatrix=camera.GetViewProjectionMatrix();
    }
    void Renderer::EndScene()
    {
    }
    void Renderer::Submit(const Hazel::Ref<VertexArray> &vertexArray,const Hazel::Ref<Shader>& shader,const glm::mat4 transform)
    {
        shader->Bind();
        std::dynamic_pointer_cast<OpenGLShader>(shader)->UploadUniformMat4("u_ViewProjection",s_SceneData->ViewProjectionMatrix);
        std::dynamic_pointer_cast<OpenGLShader>(shader)->UploadUniformMat4("u_Transform",transform);

        vertexArray->Bind();
        RendererCommand::DrawIndexed(vertexArray);
    }
}